<?php

namespace app\admin\model\vppz;

use think\Model;
use traits\model\SoftDelete;

class Qxzl extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'qxzl';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'stype_text',
        'image_url',
        'sale_type_text'
    ];




    public function getStypeList()
    {
        return ['medical_imaging'=>__('medical_imaging'),'surgical'=>__('surgical'),'rehabilitation'=>__('rehabilitation'),'other'=>__('other')];
    }


    public function getStypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getStypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


	// 获取器直接转换url
	public function getImageUrlAttr($value,$data)
    {
        return \addons\vppz\library\Vpower::dourl($data['image']);
    }
// 销售类型获取器
    public function getSaleTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['sale_type'] ?? '');
        $list = $this->getSaleTypeList();
        return is_array($value) ? implode(',', $value) : $value;
    }

    // 销售类型列表
    public function getSaleTypeList()
    {
        return ['rent' => '租赁', 'sale' => '销售'];
    }
 public function company()
    {
        return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
